package com.gem.talkbase.activity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.tsz.afinal.FinalBitmap;
import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;

import com.gem.talkbase.R;
import com.gem.talkbase.adapter.ContactAddAdapter;
import com.gem.talkbase.bean.Contacts;
import com.gem.talkbase.bean.Firend;
import com.gem.talkbase.client.Client;
import com.gem.talkbase.service.JSON_Countacts;
import com.gem.talkbase.service.JSON_Friend_info;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

/**
 *
 */
public class AddContactsActivity extends Activity {
    TextView unick,ph2,xb2,qm2;
    ImageView iV_imageView;
	String requestPath=Client.Firend_info_URL;
	List<Firend> list;
	String unameString,friendimage,friendID,username1;
	FinalBitmap fb ;

	Context context; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);	
		setContentView(R.layout.contacts_info);
		init();
		Intent intent=getIntent();
		String lxr_name=intent.getStringExtra("lxr_name");
		System.out.println(lxr_name+"=====================lxrname");
		fun(lxr_name);
		
	}
	
	public void init(){
	 unick=(TextView)findViewById(R.id.lxr_nick);
	 ph2=(TextView)findViewById(R.id.lxr_ph2);
	 xb2=(TextView)findViewById(R.id.lxr_xb2);
	 qm2=(TextView)findViewById(R.id.lxr_qm2);
	 iV_imageView=(ImageView)findViewById(R.id.lxr_iv);
		
	}
    public void fun(final String userid){
    	AjaxParams params = new AjaxParams();
		params.put("username", userid);
		FinalHttp fh = new FinalHttp();
		fh.post(requestPath, params, new AjaxCallBack<String>() {
			@Override
			public void onFailure(Throwable t, String strMsg) {
				System.out.println("加载失败！！！");
				super.onFailure(t, strMsg);
			}
			@Override
			public void onLoading(long count, long current) {
				// TODO Auto-generated method stub
				System.out.println("正在加载！！！");
				super.onLoading(count, current);
			}
		
			@Override  
			public void onSuccess(String jsonString) {
	 			super.onSuccess(jsonString);
	 			fb = FinalBitmap.create(context);
	 			list=new ArrayList<Firend>();
	 			JSON_Friend_info json_Friend_info=new JSON_Friend_info();
	 			list= json_Friend_info.info(jsonString);
				Iterator<Firend> iterator=list.iterator();
				Firend firend = null;
				while(iterator.hasNext()){ 
					firend=iterator.next();
				    unameString=firend.getUsername();//这是id
				    friendimage=firend.getUimage();//这是头像
				    System.out.println(friendimage+"===========firendimage");
				    friendID=firend.getUsername();
				    unick.setText(userid);//这也是昵称
				    ph2.setText(firend.getUsername());//这是好友id电话
				    xb2.setText(firend.getUxb());
				    qm2.setText(firend.getUstyle());
					fb.display(iV_imageView,firend.getUimage());
				 
				    } 
				}  
		});
    }
	
	
}
